<?php

/**
 * Created by PhpStorm.
 * Author: ls
 * Time: 2023/8/31 11:48
 * Desc: 订单完成
 */
class Listener_Finance_Order_Finished extends Listener_Base
{
    public function handle($args)
    {
        if (St_Functions::is_normal_app_install('supplierfinancemanage') && !empty($args['order']['supplierlist'])) {
            $self       = new self();
            $self->args = $args;
            //判断队列是否开启,如果开启则把任务推送到队列
            if ($self->queue_status) {
                //推送到队列执行
                Queue::in('default', Listener_Finance_Order_Finished::class, $args);
            } else {
                $self->perform();
            }
        }
    }


    public function perform()
    {
        $order = $this->args['order'] ?? $this->args;
        St_Log::write('供应商财务', array('status' => $order['status']), "event/order_finished/log");
        Model_Finance_Supplier::add_brokerage($order['ordersn'], $order);
        St_Log::write('供应商财务', array('ordersn' => $order['ordersn']), 'event/order_finished/log');
    }
}